package com.goods.business.controller;

import com.goods.business.service.SupplierService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author liangliang
 * @Date 2021/11/9 8:12 Administrator
 * @Description
 */
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    /**
     * 分页查询物资来源信息
     * @param pageNum
     * @param pageSize
     * @param
     * @return
     */
    @GetMapping("/findSupplierList")
    public ResponseBean findSupplierList(
                                         @RequestParam("pageNum") Integer pageNum,
                                         @RequestParam("pageSize")Integer pageSize,
                                        SupplierVO supplierVO ){
    PageVO<SupplierVO>  supplierVOPageVO=supplierService.findSupplierList(pageNum,pageSize,supplierVO);
    return ResponseBean.success(supplierVOPageVO);
    }

    /**
     * 添加物资来源信息
     * @param supplierVO
     * @return
     */
    @PostMapping("/add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO){
            supplierService.add(supplierVO);
            return ResponseBean.success();
    }

    /**
     * 通过id查询物资来源信息用作修改的数据回显
     * @param id
     * @return
     */
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Integer id){
        SupplierVO supplierVO=supplierService.edit(id);
        return ResponseBean.success(supplierVO);
    }

    /**
     * 修改物资来源信息
     * @param id
     * @param supplierVO
     * @return
     */
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,
                               @RequestBody SupplierVO supplierVO){
        supplierService.update(id,supplierVO);
        return ResponseBean.success();
    }

    /**
     * 删除物资来源信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        supplierService.delete(id);
        return ResponseBean.success();
    }

    /**
     * 查询来源信息用于入库显示
     * @return
     */
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<SupplierVO> supplierVOList=supplierService.findAll();
        return ResponseBean.success(supplierVOList);
    }
}
